<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>节点设置</title>
    <link rel="stylesheet" href="https://tstatic.dgg.net/static/plugs/DataTables/css/jquery.dataTables.css">
    <link rel="stylesheet" href="https://tstatic.dgg.net/static/plugs/layui/css/layui.min.css">
    <link rel="stylesheet" href="https://tstatic.dgg.net/static/css/dgg-iboss.min.css">
    <link rel="stylesheet" href="https://tstatic.dgg.net/static/css/dgg-plugs.min.css">
    <link rel="stylesheet" href="../../css/aptitudes.min.css">
</head>
<body>
<button class="layui-btn" onclick="addFlow()">新增流程</button>

<script src="https://tstatic.dgg.net/static/plugs/jquery/jquery-1.9.1.min.js"></script>
<script src="https://tstatic.dgg.net/static/plugs/layui/layui.all.js"></script>
<script src="https://tstatic.dgg.net/static/plugs/DataTables/js/jquery.dataTables.js"></script>
<script src="https://tstatic.dgg.net/static/plugs/DataTables/js/dataTables.fixedColumns.min.js"></script>
<script src="https://tstatic.dgg.net/static/plugs/DataTables/js/dataTable.extend.js"></script>
<script src="https://tstatic.dgg.net/static/js/dgg-foot-base.js"></script>
<script>
    var nodeFlowIndex;
    function addFlow() {
        $.ajax({
            url:'nodeSetAjax.html',
            dataType:'html',
            success:function(res){
                nodeFlowIndex=dgg.Open({
                    title: '新增流程',
                    content: res,
                    area: '70%',
                })
            }
        })
    }
    <!--新增行-->
    function addRow(obj) {
        var trHtm='<tr>' +
            '            <td><input type="text" class="table-input" /></td>\n' +
            '            <td><input type="text" class="table-input" /></td>\n' +
            '            <td><input type="text" class="table-input" /></td>\n' +
            '            <td>\n' +
            '                <select class="table-select">\n' +
            '                    <option value="0">是</option>\n' +
            '                    <option value="1">否</option>\n' +
            '                </select>\n' +
            '            </td>\n' +
            '            <td>\n' +
            '                <a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,1)">上移</a>\n' +
            '                <a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,2)">下移</a>\n' +
            '            </td>\n' +
            '            <td>\n' +
            '                <a href="javascript:void(0)" class="iboss-link" onclick="removeRow(this)">删除</a>\n' +
            '            </td>\n' +
            '        </tr>'
        $(obj).parents('table').find('tbody').append(trHtm);
        tableEach()
    }
    //删除行
    function removeRow(obj) {
        $(obj).parents('tr').remove();
        tableEach()
    }
    //上下移动行
    function moveFun(obj,move) {
        var trHtm=$(obj).parents('tr').html();
        trHtm='<tr>'+trHtm+'</tr>';
        /*获取移动行内输入框的val*/
        var tdLen=$(obj).parents('tr').find('td').length-2;
        var tdData={};
        $(obj).parents('tr').find('td').each(function (i) {
            if(i<tdLen) {
                tdData[i]=$(this).children().val();
            }
        });
        if(move==1) {
            //上移
            $(obj).parents('tr').prev().before(trHtm);
            $(obj).parents('tr').prev().prev().find('td').each(function (j) {
                $(this).children().val(tdData[j])
            })
        }
        else {
            //下移
            $(obj).parents('tr').next().after(trHtm);
            $(obj).parents('tr').next().next().find('td').each(function (j) {
                $(this).children().val(tdData[j])
            })
        }
        $(obj).parents('tr').remove();
        tableEach();
    }
    function tableEach(obj) {
        dgg.relocation(nodeFlowIndex);
        var trLen=$('.nodeTable').find('tbody').find('tr').length;
        if(trLen==1){
            $('.nodeTable').find('tbody').find('tr').children().eq(4).hide();
        }else {
            $('.nodeTable').find('tbody').find('tr').children().eq(4).show();
        }
        $('.nodeTable').find('tbody').find('tr').each(function (i) {
            if(i==0) {
                $(this).children().eq(4).empty().append('<a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,2)">下移</a>');
            }else if(i==trLen-1) {
                $(this).children().eq(4).empty().append('<a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,1)">上移</a>')
            }else {
                $(this).children().eq(4).empty().append('<a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,1)">上移</a>' +
                    '<a href="javascript:void(0)" class="iboss-link" onclick="moveFun(this,2)">下移</a>');
            }
        })
    }
</script>
</body>
</html>